/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FindProductPanel.java
 *
 * Created on 11-06-2010, 10:16:01
 */
package gruppe1projekt.GUILayer.rent;

import gruppe1projekt.ControllerLayer.RentController;
import gruppe1projekt.GUILayer.BaseWindow;
import gruppe1projekt.GUILayer.SearchList;
import gruppe1projekt.ModelLayer.RentableItem;
import javax.swing.JOptionPane;

/**
 *
 * @author Evil-j
 */
public class editRentableItemPanel extends BaseWindow {

    SearchList<RentableItem> list;
    RentController ctr;

    /** Creates new form FindProductPanel */
    public editRentableItemPanel() {
        initComponents();

        this.RequiresLogin = true;

        ctr = new RentController();

        list = new SearchList(ctr.getRentableItems());
        insertPanel(pnlSearchBox, list);

        this.add(list);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        pnlSearchBox = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        lblType = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        lblDayPrice = new javax.swing.JLabel();
        ShowButton = new javax.swing.JButton();
        lblSerialNumber = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        deleteButton = new javax.swing.JButton();
        updateButton = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        lblDescription = new javax.swing.JTextArea();
        jPanel2 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        lblSerialNumber2 = new javax.swing.JLabel();
        txtType = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtDescription = new javax.swing.JTextArea();
        txtDayPrice = new javax.swing.JTextField();
        SaveButton = new javax.swing.JButton();
        lblTypeAlert = new javax.swing.JLabel();
        lblDayPriceAlert = new javax.swing.JLabel();
        lblDescriptionAlert = new javax.swing.JLabel();

        setMaximumSize(new java.awt.Dimension(618, 580));
        setMinimumSize(new java.awt.Dimension(618, 580));
        setPreferredSize(new java.awt.Dimension(618, 580));

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Find Udlejnings produkt", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Verdana", 1, 14))); // NOI18N
        jPanel1.setMaximumSize(null);
        jPanel1.setMinimumSize(null);
        jPanel1.setPreferredSize(new java.awt.Dimension(594, 285));

        pnlSearchBox.setMaximumSize(null);
        pnlSearchBox.setVerifyInputWhenFocusTarget(false);

        javax.swing.GroupLayout pnlSearchBoxLayout = new javax.swing.GroupLayout(pnlSearchBox);
        pnlSearchBox.setLayout(pnlSearchBoxLayout);
        pnlSearchBoxLayout.setHorizontalGroup(
            pnlSearchBoxLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 229, Short.MAX_VALUE)
        );
        pnlSearchBoxLayout.setVerticalGroup(
            pnlSearchBoxLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 236, Short.MAX_VALUE)
        );

        jLabel3.setText("Beskrivelse:");

        lblType.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        lblType.setMaximumSize(new java.awt.Dimension(180, 20));
        lblType.setMinimumSize(new java.awt.Dimension(180, 20));
        lblType.setPreferredSize(new java.awt.Dimension(180, 20));

        jLabel7.setText("Dags pris:");

        lblDayPrice.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        lblDayPrice.setMaximumSize(new java.awt.Dimension(180, 20));
        lblDayPrice.setMinimumSize(new java.awt.Dimension(180, 20));
        lblDayPrice.setOpaque(true);
        lblDayPrice.setPreferredSize(new java.awt.Dimension(180, 20));

        ShowButton.setText("Vis info");
        ShowButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ShowButtonActionPerformed(evt);
            }
        });

        lblSerialNumber.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        lblSerialNumber.setMaximumSize(new java.awt.Dimension(180, 20));
        lblSerialNumber.setMinimumSize(new java.awt.Dimension(180, 20));
        lblSerialNumber.setPreferredSize(new java.awt.Dimension(180, 20));

        jLabel1.setText("Serienummer:");

        jLabel2.setText("Type:");

        deleteButton.setText("Slet produkt");
        deleteButton.setEnabled(false);
        deleteButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteButtonActionPerformed(evt);
            }
        });

        updateButton.setText("Rediger info");
        updateButton.setEnabled(false);
        updateButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                updateButtonActionPerformed(evt);
            }
        });

        jScrollPane2.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jScrollPane2.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        jScrollPane2.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
        jScrollPane2.setMaximumSize(new java.awt.Dimension(180, 90));
        jScrollPane2.setMinimumSize(new java.awt.Dimension(180, 90));
        jScrollPane2.setPreferredSize(new java.awt.Dimension(180, 90));

        lblDescription.setColumns(20);
        lblDescription.setEditable(false);
        lblDescription.setLineWrap(true);
        lblDescription.setRows(5);
        lblDescription.setBorder(null);
        lblDescription.setHighlighter(null);
        lblDescription.setMaximumSize(new java.awt.Dimension(180, 90));
        lblDescription.setMinimumSize(new java.awt.Dimension(180, 90));
        lblDescription.setOpaque(false);
        lblDescription.setPreferredSize(new java.awt.Dimension(180, 90));
        jScrollPane2.setViewportView(lblDescription);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(30, 30, 30)
                .addComponent(pnlSearchBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(ShowButton)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3)
                            .addComponent(jLabel7)
                            .addComponent(jLabel1))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblSerialNumber, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(lblDayPrice, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(lblType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(updateButton)
                        .addGap(18, 18, 18)
                        .addComponent(deleteButton)))
                .addContainerGap(41, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(pnlSearchBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(ShowButton)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel1))
                            .addComponent(lblSerialNumber, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(lblType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(10, 10, 10)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel7)
                            .addComponent(lblDayPrice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(deleteButton)
                            .addComponent(updateButton))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Rediger udlejnings produkt", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Verdana", 1, 14))); // NOI18N
        jPanel2.setMaximumSize(null);
        jPanel2.setMinimumSize(null);
        jPanel2.setPreferredSize(new java.awt.Dimension(594, 268));

        jLabel4.setText("Beskrivelse:");

        jLabel5.setText("Serienummer:");

        jLabel6.setText("Type:");

        jLabel8.setText("Dags pris");

        lblSerialNumber2.setMaximumSize(new java.awt.Dimension(160, 20));
        lblSerialNumber2.setMinimumSize(new java.awt.Dimension(160, 20));
        lblSerialNumber2.setPreferredSize(new java.awt.Dimension(160, 20));

        txtType.setMaximumSize(new java.awt.Dimension(160, 20));
        txtType.setMinimumSize(new java.awt.Dimension(160, 20));
        txtType.setPreferredSize(new java.awt.Dimension(160, 20));
        txtType.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtTypeActionPerformed(evt);
            }
        });

        jScrollPane1.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        jScrollPane1.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
        jScrollPane1.setMaximumSize(new java.awt.Dimension(160, 90));
        jScrollPane1.setMinimumSize(new java.awt.Dimension(160, 90));
        jScrollPane1.setPreferredSize(new java.awt.Dimension(160, 90));

        txtDescription.setColumns(20);
        txtDescription.setLineWrap(true);
        txtDescription.setRows(5);
        txtDescription.setMaximumSize(new java.awt.Dimension(160, 90));
        txtDescription.setMinimumSize(new java.awt.Dimension(160, 90));
        txtDescription.setPreferredSize(new java.awt.Dimension(160, 90));
        jScrollPane1.setViewportView(txtDescription);

        txtDayPrice.setMaximumSize(new java.awt.Dimension(160, 20));
        txtDayPrice.setMinimumSize(new java.awt.Dimension(160, 20));
        txtDayPrice.setPreferredSize(new java.awt.Dimension(160, 20));
        txtDayPrice.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtDayPriceActionPerformed(evt);
            }
        });

        SaveButton.setText("Gem ændringer");
        SaveButton.setEnabled(false);
        SaveButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SaveButtonActionPerformed(evt);
            }
        });

        lblTypeAlert.setForeground(new java.awt.Color(255, 0, 0));
        lblTypeAlert.setMaximumSize(new java.awt.Dimension(160, 20));
        lblTypeAlert.setMinimumSize(new java.awt.Dimension(160, 20));
        lblTypeAlert.setPreferredSize(new java.awt.Dimension(160, 20));

        lblDayPriceAlert.setForeground(new java.awt.Color(255, 0, 0));
        lblDayPriceAlert.setMaximumSize(new java.awt.Dimension(160, 20));
        lblDayPriceAlert.setMinimumSize(new java.awt.Dimension(160, 20));
        lblDayPriceAlert.setPreferredSize(new java.awt.Dimension(160, 20));

        lblDescriptionAlert.setForeground(new java.awt.Color(255, 0, 0));
        lblDescriptionAlert.setMaximumSize(new java.awt.Dimension(160, 20));
        lblDescriptionAlert.setMinimumSize(new java.awt.Dimension(160, 20));
        lblDescriptionAlert.setPreferredSize(new java.awt.Dimension(160, 20));

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel6)
                                    .addComponent(jLabel8)
                                    .addComponent(jLabel5))
                                .addGap(18, 18, 18)
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(lblSerialNumber2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(txtType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(lblTypeAlert, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addComponent(txtDayPrice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                            .addComponent(lblDayPriceAlert, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblDescriptionAlert, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(SaveButton))
                .addContainerGap(76, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(26, 26, 26)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel5)
                    .addComponent(lblSerialNumber2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(17, 17, 17)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel6)
                            .addComponent(txtType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4))
                        .addGap(10, 10, 10)
                        .addComponent(lblTypeAlert, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(17, 17, 17)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel8)
                            .addComponent(txtDayPrice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(lblDayPriceAlert, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(lblDescriptionAlert, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(SaveButton)
                .addContainerGap(30, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(14, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 278, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, 274, Short.MAX_VALUE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void deleteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteButtonActionPerformed
        int SelectedOption = JOptionPane.showConfirmDialog(this, "Er du sikker på du vil slette produktet?");
        
        if (SelectedOption == JOptionPane.OK_OPTION) 
        {
            ctr.deleteRentableItem(Long.parseLong(lblSerialNumber.getText()));
            list.setItems(ctr.getRentableItems());

            clearActionShow();
            clearActionUpdate();

            JOptionPane.showMessageDialog(this, "Produktet er slettet.");
        }
    }//GEN-LAST:event_deleteButtonActionPerformed

    private void ShowButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ShowButtonActionPerformed
        RentableItem rent = list.GetSelectedItem();

        if (rent != null) 
        {
            updateButton.setEnabled(true);
            deleteButton.setEnabled(true);

            lblSerialNumber.setText(String.valueOf(rent.getSerialNumber()));
            lblType.setText(rent.getType());
            lblDescription.setText(rent.getDescription());
            lblDayPrice.setText(String.valueOf(rent.getDayPrice()));
        }
    }//GEN-LAST:event_ShowButtonActionPerformed

    private void updateButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_updateButtonActionPerformed
        SaveButton.setEnabled(true);

        RentController ctr = new RentController();
        RentableItem item = ctr.readRentableItem(Long.parseLong(lblSerialNumber.getText()));

        lblSerialNumber2.setText(Long.valueOf(item.getSerialNumber()).toString());
        txtType.setText(item.getType());
        txtDescription.setText(item.getDescription());
        txtDayPrice.setText(Double.valueOf(item.getDayPrice()).toString());

        clearActionShow();
    }//GEN-LAST:event_updateButtonActionPerformed

    private void txtTypeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtTypeActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtTypeActionPerformed

    private void SaveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SaveButtonActionPerformed
        int selectedOption = JOptionPane.showConfirmDialog(this, "Er du sikker på at du vil redigere produktet?");
        if(selectedOption == JOptionPane.OK_OPTION)
        {
            if (IsValid()) {
                RentController ctr = new RentController();
                RentableItem item = ctr.readRentableItem(Long.parseLong(lblSerialNumber2.getText()));

                if (item != null) {
                    item.setType(txtType.getText());
                    item.setDescription(txtDescription.getText());
                    item.setDayPrice(Double.valueOf(txtDayPrice.getText().toString()));

                    clearActionShow();
                    clearActionUpdate();
                    
                    JOptionPane.showMessageDialog(this, "Oplysningerne er gemt.");
                }
            } else {
                JOptionPane.showMessageDialog(this, "Nogle af informationerne er ikke blevet tastet korrekt ind.");

            }
        }
    }//GEN-LAST:event_SaveButtonActionPerformed

    private void txtDayPriceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtDayPriceActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtDayPriceActionPerformed

    @Override
    public boolean IsValid() {
        if (txtType.getText().equals("")) {
            lblTypeAlert.setText("Du skal skrive noget i denne teksboks.");
            return false;
        }

        if (txtDescription.getText().equals("")) {
            lblDescriptionAlert.setText("Du skal skrive noget i denne teksboks.");
            return false;
        }

        if (txtDayPrice.getText().equals("")) {
            lblDayPriceAlert.setText("Du skal skrive noget i denne teksboks.");
            return false;
        }

        if (!isDouble(txtDayPrice.getText())) {
            lblDayPriceAlert.setText("Der må kun stå tal i dette felt.");
            return false;
        }

        RentController ctr = new RentController();
        RentableItem item = ctr.readRentableItem(Long.parseLong(lblSerialNumber2.getText()));

        if (item == null) {
            return false;
        }

        return true;
    }

    private void clearActionShow()
    {
        lblSerialNumber.setText("");
        lblType.setText("");
        lblDescription.setText("");
        lblDayPrice.setText("");
        updateButton.setEnabled(false);
        deleteButton.setEnabled(false);
    }

    private void clearActionUpdate()
    {
        lblSerialNumber2.setText("");
        txtType.setText("");
        txtDescription.setText("");
        txtDayPrice.setText("");
        SaveButton.setEnabled(false);
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton SaveButton;
    private javax.swing.JButton ShowButton;
    private javax.swing.JButton deleteButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JLabel lblDayPrice;
    private javax.swing.JLabel lblDayPriceAlert;
    private javax.swing.JTextArea lblDescription;
    private javax.swing.JLabel lblDescriptionAlert;
    private javax.swing.JLabel lblSerialNumber;
    private javax.swing.JLabel lblSerialNumber2;
    private javax.swing.JLabel lblType;
    private javax.swing.JLabel lblTypeAlert;
    private javax.swing.JPanel pnlSearchBox;
    private javax.swing.JTextField txtDayPrice;
    private javax.swing.JTextArea txtDescription;
    private javax.swing.JTextField txtType;
    private javax.swing.JButton updateButton;
    // End of variables declaration//GEN-END:variables
}
